<?php

include_once($cfgPaths['lib'].'cms/type/cmsEditType.o.inc.php');

class cmsEditNavType extends cmsEditType {

 function registerFields () {
   $map[] = $this->name.'navname';
   $map[] = $this->name.'paramstr';
   $this->map = &$map;
 }

 function render_html () {
    global $cfgPaths,$cfgDeveloperMode,$env;
    $navname = $this->getValue($this->name.'navname');
    $html  = '<table border="0" cellspacing="0" cellpadding="0" width="100%">'."\n";
    $html .= '  <tr>'."\n";
    $html .= '    <td bgcolor="#000000">'."\n";
    $html .= '      <table border="0" cellspacing="1" cellpadding="3" width="100%">'."\n";
    $html .= '     </tr>'."\n";
    $html .= '        <tr>'."\n";
    $html .= '          <td width="100" bgcolor="#E0F6FD" valign="top">'."\n";
    $html .= '              <b>'.$this->descr.':</b>'.$this->showFields().'</td>'."\n";
    $html .= '          <td bgcolor="#E0F6FD">'."\n";
    $html .= '  <table border="0">'."\n";
    $html .= '     <tr>'."\n";
    $html .= '      <td>Parameter:</td>'."\n";
    $html .= '      <td>'."\n";
    $html .= '        <input tabindex="'.$this->sender->getNextTabindex($this->name.'paramstr').'" name="'.$this->name.'paramstr" value="'.htmlspecialchars($this->getValue($this->name.'paramstr')).'" size="50" maxlength="255"><td>'."\n";
    $html .= '     </tr>'."\n";
    $html .= '     <tr>'."\n";
    $html .= '      <td>Navigation:</td>'."\n";
    $html .= '      <td>'."\n";
    $html .= '<select tabindex="'.$this->sender->getNextTabindex($this->name.'navname').'" name="'.$this->name.'navname">'."\n";
    $dir = $cfgPaths['template'].'cms/nav/';
    if ($cfgDeveloperMode)
    {
        if (file_exists($dir)){
            $dh = opendir($dir);
            rewinddir($dh);
            while($file = readdir($dh)){
                if (!is_dir($dir.$file)){
                    $html .= '<option';
                    if ($file==$navname)
                        $html .= " selected";
                    $html .= '>'.$file.'</option>';
                }
            }
        }
    }
    else
    {
        $els = $GLOBALS['tdba']->getBySiteAndType($env->getSession('s_currentSite'),'nav');
        for ($i=0;$i<count($els);$i++)
        {
            $html .= '<option';
            if ($navname==$els[$i]['filename']) 
                $html .= " selected";
            $html .= ' value="'.urlencode($els[$i]['filename']).'">'.$els[$i]['name'].'</option>';
        }
    }
    $html .= '</select></td>'."\n";
    $html .= '     </tr>'."\n";
    $html .= '  </table>'."\n";
    $html .= '        </td></tr>'."\n";
    $html .= '      </table></td>'."\n";
    $html .= '  </tr>'."\n";
    $html .= '</table><br>'."\n";
    return $html;
 }

 function render_javascript () {
 }

}


?>